package com.sanjiahantang.youjiarole.module.goods.views.impl;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.uilibrary.views.TagGroup;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.module.goods.presenters.ReduceMoneyPresenter;
import com.sanjiahantang.youjiarole.module.goods.views.GoodsView;
import com.sanjiahantang.youjiarole.module.me.order.beans.ShopListBean;
import com.sanjiahantang.youjiarole.utils.FileUtils;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * 退款详情
 * Created by zy on 2017/12/8.
 */

public class ReduceMoneyActivity extends BaseMvpActivity<GoodsView,ReduceMoneyPresenter> implements GoodsView, View.OnClickListener {

    private TextView txtOrderNum,txtState,txtAmount;
    private ImageView ivState;
    private HashMap<Integer,String> statusNameMap;
    private HashMap<Integer,Integer> statusResMap;
    private ShopListBean.Data.GoodsInfoDtoListBean goodsData;
    private ListView goodListView;

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public ReduceMoneyPresenter initPresenter() {
        return new ReduceMoneyPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_reduce_money);

        initTitle();
        initConstance();

        txtOrderNum = (TextView) findViewById(R.id.txtOrderNum);
        txtOrderNum.setText("退款信息");

        goodsData = (ShopListBean.Data.GoodsInfoDtoListBean) getIntent().getSerializableExtra(KEY_PARAM);
        if (goodsData == null){
            Utils.showToast($this,"参数传递错误");
            finish();
            return;
        }
        txtState = (TextView) findViewById(R.id.txtState);
        txtState.setText(statusNameMap.get(goodsData.getStatusId()));

        ivState = (ImageView) findViewById(R.id.ivState);
        ivState.setImageResource(statusResMap.get(goodsData.getStatusId()));

        goodListView = (ListView) findViewById(R.id.goodListView);
        List<ShopListBean.Data.GoodsInfoDtoListBean> list = new ArrayList<>();
        list.add(goodsData);
        goodListView.setAdapter(new QuickAdapter<ShopListBean.Data.GoodsInfoDtoListBean>($this,R.layout.item_order_goods,list) {
            @Override
            protected void convert(BaseAdapterHelper helper, final ShopListBean.Data.GoodsInfoDtoListBean item) {
                helper.setText(R.id.txtTitle,item.getRecordName());
                helper.setText(R.id.txtPrice,String.valueOf(item.getPrice()));
                helper.setText(R.id.txtNumber,String.valueOf(item.getCount()));
                TagGroup tagGroup = helper.getView(R.id.tgScale);
                if (item.getMgpiValue() != null){
                    tagGroup.setTags(item.getMgpiValue());
                }
                Picasso.with($this).load(FileUtils.rePath(item.getUrl())).placeholder(RES_ID_GOODS_DEFAULT).into((ImageView) helper.getView(R.id.imgGoods));
                helper.setOnClickListener(R.id.ll_ogitem, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, GoodsDetailActivity.class);
                        intent.putExtra("goodsId", item.getMgiId());
                        context.startActivity(intent);
                    }
                });
            }
        });

        txtAmount = (TextView) findViewById(R.id.txtAmount);
        txtAmount.setText(goodsData.getReduceMoney());
    }

    private void initTitle() {
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("退款详情");
        findViewById(R.id.fl_Left).setOnClickListener(this);
    }

    private void initConstance() {
        statusNameMap = new HashMap<>();
        statusResMap = new HashMap<>();

        statusNameMap.put(4,"退款审核中");
        statusNameMap.put(6,"退款完成");
        statusNameMap.put(8,"退款关闭");
        statusNameMap.put(10,"退款关闭");
        statusNameMap.put(9,"退款关闭");

        statusResMap.put(4,R.drawable.i_reduce_wait);
        statusResMap.put(6,R.drawable.i_reduce_suc);
        statusResMap.put(8,R.drawable.i_reduce_fail);
        statusResMap.put(10,R.drawable.i_reduce_fail);
        statusResMap.put(9,R.drawable.i_reduce_fail);
    }

    @Override
    public void initData() {
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.fl_Left:
                finish();
                break;
        }
    }
}
